@extends('Layouts.iframe')
@section('content')
    <style>
        .agent-operate{
            text-align: center;
            margin-top: 10%;
        }
        .portfolio-area li{
            height: 200px;
        }
    </style>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 机构管理 <span class="c-gray en">&gt;</span> 机构列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-l">
            <form action="{{route('agent.index')}}" method="get">
                机构名称：
                <input type="text" name="keyword" id="" value="{{$agents->keyword}}" placeholder="输入机构名称进行搜索" style="width:250px" class="input-text">
                <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> </button>
            </form>
        </div>
        @can('agent.create')
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="r">
                <a class="btn btn-primary radius" onclick="agent_add('添加机构','{{route('agent.create')}}','','510')" href="javascript:;">
                    <i class="Hui-iconfont">&#xe600;</i>新增机构
                </a>
            </span>
        </div>
        @endcan
        <div class="portfolio-content">
            <ul class="cl portfolio-area">
                @if($agents->count())
                    @foreach($agents as $agent)
                        <li class="item">
                            <div class="portfoliobox">
                                <div class="picbox">
                                    <a href="#" data-lightbox="gallery" data-title="{{$agent->name}}">
                                        <img src="{{env('IMG_URL').$agent->logo}}">
                                    </a>
                                </div>
                                <div class="agent-operate">
                                    {{--<a href="#" class="label label-success radius">查看</a>--}}
                                    @can('agent.edit')
                                        <a href="#" onclick="agent_add('添加机构','{{route('agent.edit',['id'=>$agent->id])}}','','510')" class="label label-primary radius">编辑</a>
                                    @endcan
                                    @can('agent.destroy')
                                        <a href="#" onClick="agent_del(this,'{{$agent->id}}')" title="删除" class="label label-danger radius">删除</a>
                                    @endcan
                                </div>
                            </div>
                        </li>
                    @endforeach
                @endif
            </ul>
        </div>
        <div id="pull_right">
            <div class="pull-right">
                {!! $agents->render() !!}
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        /*机构-添加/编辑*/
        function agent_add(title,url,w,h){
            layer_show(title,url,w,h);
        }
        /*机构删除*/
        function agent_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    type: 'POST',
                    url: "{{url('admin/agent')}}/"+id,
                    data:{'_method':'DELETE','_token':"{{csrf_token()}}"},
                    dataType: 'json',
                    success: function (data) {
                        if(data.status===200){
                            $(obj).parents("li").remove();
                            layer.msg('删除成功!', {icon: 1, time: 2000});
                        }else {
                            layer.msg(data.msg, {icon: 1, time: 2000});
                        }
                    },
                    error: function (data) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        console.log(data.msg);
                    },
                });
            });
        }
    </script>
@endsection